package com.lk.springboot.dao;

import com.lk.springboot.pojo.SitesRu;
import com.lk.springboot.pojo.UmDonation;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author lk
 * @date 2020/1/12 0012 14:55
 */
@Mapper
public interface SitesMapper {

    // 站点兑换中心概述
    @Select("select  * from sites_ru ")
    List<SitesRu> getSitesSummary();

    // 获取指定规则详情
    @Select("select  * from sites_ru where siru_id=#{siru_id}")
    SitesRu getSitesDetail(String siru_id);

    //获取已捐赠的伞的数量
    @Select("select count(*) FROM donate_um ")
    int getUMCount();

    //-----------------------------------------------------------------------------------------------
    // 获取用户已获得所有能用于兑换的站点
    @Select("select s_id from ((select s_id from u_s_have where u_id=#{u_id}  group by sp_id ) as a  ) group by a.s_id having count(a.s_id)=4")
    List<String> getAllokSP(String u_id);

    // 减少  指定用户 的 指定站点 的 一套拼图（留下剩余拼图）
    @Delete("delete from u_s_have where has_id in (select has_id from (select has_id from u_s_have where u_id=#{u_id} and s_id=#{s_id} group by sp_id ) t1) ")
    void reduceSites(@Param("u_id") String u_id, @Param("s_id") String s_id);

    // 增加捐伞记录
    @Insert("insert into donate_um(u_id,um_id,date) values(#{u_id},#{um_id},#{date}) ")
    void addDonateUM(UmDonation umDonation);

    // 标记捐伞任务完成，任务进度标记为1，完成*
    @Update("update  u_t_solve set speed = 1 where u_id=#{u_id} and t_id = 't10004' and speed < 999 ")
    void signUmbrella(String u_id);

    // 根据u_id查询用户 姓名
    @Select("select u_name from users where u_id=#{u_id} ")
    String getUName(String u_id);

    // 根据um_id查询伞的位置
    @Select("select place from umbrella where um_id = #{um_id} ")
    String getPlace(String um_id);

    // 获取用户已获得所有能用于兑换的站点 的数量
    @Select(" select min(sites_sp_num) from ((SELECT count(sp_id) sites_sp_num from u_s_have WHERE u_id=#{u_id} and s_id=#{s_id} GROUP BY sp_id) as lk )")
    Integer getAllokSPNum(@Param("u_id") String u_id, @Param("s_id") String s_id);

    // 有新消息未读，更改通知状态为有新消息（0无，1有）
    @Update("update users set news = 1 where u_id = #{u_id}")
    void updateNewsYes(String u_id);

}
